package com.nebula.common.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.parser.Feature;

/**
 * Created by Mtime on 2017/9/1.
 */

public class JsonEncoder implements StringEncoder {
    public static final JsonEncoder DEFAULT = new JsonEncoder();

    public JsonEncoder() {
    }

    public String encode(Object obj) {
        return JSON.toJSONString(obj);
    }

    public <T> T decode(String value, Class<T> clazz) {
        return JSON.parseObject(value, clazz);
    }

    public <T> T decode(String value, TypeWrapper<T> type) {
        return JSON.parseObject(value, type.getType(), new Feature[0]);
    }
}